/*
 * display_func.c
 *
 *  Created on: Jan 21, 2014
 *      Author: Raviraj
 */

#include"includes.h"

extern FILE *TRACE;

void print_contents(void)
{
	printf("\n");printf("\n");
	printf("\n  R0 = %.6o \t\tR1 = %.6o ", read_from_memory(R0,DATA),read_from_memory(R1,DATA));
	printf("\n");
	printf("\n  R2 = %.6o \t\tR3 = %.6o ", read_from_memory(R2,DATA),read_from_memory(R3,DATA));
	printf("\n");
	printf("\n  R4 = %.6o \t\tR5 = %.6o ", read_from_memory(R4,DATA),read_from_memory(R5,DATA));
	printf("\n");
	printf("\n  SP = %.6o \t\tPC = %.6o ", read_from_memory(SP,DATA),read_from_memory(PC,DATA));
	printf("\n");
	printf("\n  Zero flag = %u \tNegative flag = %u ", get_Z_flag(),get_N_flag());
	printf("\n");
	printf("\n  Overflow flag = %u \tCarry flag = %u ", get_V_flag(),get_C_flag());
	printf("\n");printf("\n");
}

void print_mem_loc(void)
{
	printf("\n");printf("\n");
	printf("                   VALID MEMORY CONTENTS                   \n");
	int _index=0;
	for(_index=0; _index<WORDS; _index++)
		if((_index*2) == R0 || (_index*2) == R1 || (_index*2) == R2 || (_index*2) == R3 || (_index*2) == R4 || (_index*2) == R5 || (_index*2) == PC || (_index*2) == SP || (_index*2) == PS)
			continue;
		else
			if(get_memory_status(_index*2) == VALID_WORD)
				//printf("\nM[%.6o] = (o) %.6o, (d) %d, (h) %.4x", _index, read_from_memory(_index,DATA), read_from_memory(_index,DATA), read_from_memory(_index,DATA));
				printf("\n  Memory location [%.6o] contains %.6o",_index*2,read_from_memory(_index*2,-1));

	printf("\n  Memory location [%.6o] contains %.6o",138,read_from_memory(138,-1));
	printf("\n");
}

void write_traces(int type, unsigned short address)
{
	int print_en;
	if(type == 0 || type == 1) {
		if(address == R0
		|| address == R1
		|| address == R2
		|| address == R3
		|| address == R4
		|| address == R5
		|| address == SP
		|| address == PC
		|| address == PS) {
			print_en = 0;
		} else {
			print_en = 1;
		}
	} else {
		print_en = 1;
	}

	if(print_en) {
		fprintf(TRACE, "%d %.6o\n", type, address);
	}
}
